import request from '@/utils/request'
import type { Sample, SampleQuery } from '@/types/sample'
import type { ResponseData } from '@/types/common'

// 获取样片列表
export const getSamplesList = (params?: {
  keyword?: string
  is_public?: boolean
  sort_status?: string
  page?: number
  pageSize?: number
  photographer_id?: number
}) => {
  return request.get<{
    code: number
    data: {
      items: Sample[]
      meta: {
        total: number
        page: number
        pageSize: number
        totalPage: number
      }
    }
    message: string
  }>('/samples/list', {
    params: {
      keyword: params?.keyword || '',
      is_public: params?.is_public,
      page: params?.page || 1,
      pageSize: params?.pageSize || 12,
      sort_status: params?.sort_status || 'newest',
      photographer_id: params?.photographer_id,
    },
  })
}

// 获取样片列表
export const getSamplesPublicList = (params?: {
  keyword?: string
  is_public?: boolean
  sort_status?: string
  page?: number
  pageSize?: number
  photographer_id?: number
}) => {
  return request.get<{
    code: number
    data: {
      items: Sample[]
      meta: {
        total: number
        page: number
        pageSize: number
        totalPage: number
      }
    }
    message: string
  }>('/samples/public/list', {
    params: {
      keyword: params?.keyword || '',
      is_public: params?.is_public,
      page: params?.page || 1,
      pageSize: params?.pageSize || 12,
      sort_status: params?.sort_status || 'newest',
      photographer_id: params?.photographer_id,
    },
  })
}

// 创建样片
export const createSample = (data: {
  title: string
  description: string
  tags: string[]
  is_public: boolean
  shooting_date: string
  photographer_id: number
}) => {
  return request.post<ResponseData>('/samples', data)
}

// 更新样片信息
export const updateSample = (
  id: number,
  data: {
    title?: string
    description?: string
    tags?: string[]
    is_public?: boolean
    shooting_date?: string
    photographer_id?: number
  },
) => {
  return request.patch<ResponseData>(`/samples/${id}`, data)
}

// 更新样片照片
export const updateSamplePhotos = (id: number, data: { photos: string[] }) => {
  return request.patch<ResponseData>(`/samples/${id}/photos`, data)
}

// 更新样片状态(上架/下架)
export const updateSampleStatus = (id: number) => {
  return request.patch<ResponseData>(`/samples/${id}/status`)
}

// 删除样片
export const deleteSample = (id: number) => {
  return request.delete<ResponseData>(`/samples/${id}`)
}

// 点赞样片
export const likeSample = (id: number) => {
  return request.post<ResponseData>(`/samples/${id}/like`)
}

// 取消点赞
export const unlikeSample = (id: number) => {
  return request.delete<ResponseData>(`/samples/${id}/like`)
}
